<?php

class ForumThread extends BaseForumThread{

	
	/**
	 * 
	 * Gets the post count!
	 */
	public function postCount(){
		return count($this->ThreadPosts)-1;
	}
	

	/**
	 * 
	 * Gets the URL.
	 */
	public function getURL(){
		return Module::get('Forum')->linkTo(array('t',$this->id, urlencode($this->title)));
	}
	
	
	public function getLastPost(){
		$q = Doctrine_Query::create()
		->select('fp.id, fp.created_at, fp.updated_at, title, body
		')
		->from('ThreadPost tp')
		->where('tp.forum_thread_id = ?', $this->id)
		->orderBy('tp.created_at DESC')
		->limit(1);
		
		return $q->execute()->getFirst();
	}
	
	public function getPosts(){
		return $this->ThreadPosts;
	}
}
